﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Xml;
using DataAccessLayer.Entites;

namespace DataAccessLayer.DAL
{
    public class UserDAL
    {

        public List<User> GetUser()
        {
            var list = new List<User>();
            var xmld = new XmlDocument();
            xmld.Load(HttpContext.Current.Server.MapPath("~/XML/User.xml"));
            var xmlnl = xmld.SelectNodes("/users/user");
            foreach (XmlNode xn in xmlnl)
            {
                var t = new User
                {
                    Id = xn["id"].InnerText,
                    Username = xn["username"].InnerText,
                    Password = xn["password"].InnerText,
                    IsAdmin = xn["isAdmin"].InnerText
                };
                list.Add(t);
            }
            return list;
        }

        public bool CheckValidUser(string userName, string password)
        {
            var isValidUser = false;
            var list = GetUser();
            foreach (var user in list)
            {
                if (!user.Username.Equals(userName)) continue;
                if (user.Password.Equals(password))
                    isValidUser = true;
            }
            return isValidUser;
        }
    }
}